package com.gupao.core;

import java.io.InputStream;

/**
 * Created by Devin on 2018/1/9.
 */
public class JRequest {
    private InputStream inputStream;
    private String url;
    private String method;

    public JRequest() {
    }

    public JRequest(InputStream inputStream) {
        this.inputStream = inputStream;
        try {
            String content =null;
            byte[] buff = new byte[1024];
            int len =0;
            if((len =inputStream.read(buff)) > 0){
                content = new String(buff,0,len);
            }
            extractFields(content);
        }catch (Exception e){

        }
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    private void extractFields(String content){
        String command = content.split("\\n")[0];
        String[] words = command.split("\\s");
        setMethod(words[0]);
        setUrl(words[1]);
    }
}
